What is @slack/logger?
@slack/logger is a simple and flexible logging library designed for use with Slack applications. It provides various logging levels and is easy to integrate into your Slack app to help with debugging and monitoring.
What are @slack/logger's main functionalities?
Basic Logging
This feature allows you to log messages at different levels such as info, error, warn, and debug. The code sample demonstrates how to create a logger instance and log messages at the info and error levels.
const { Logger } = require('@slack/logger');
const logger = new Logger();
logger.info('This is an info message');
logger.error('This is an error message');
Custom Log Levels
You can set custom log levels to control the verbosity of the logs. The code sample shows how to set the log level to 'debug' and log a debug message.
const { Logger } = require('@slack/logger');
const logger = new Logger();
logger.setLevel('debug');
logger.debug('This is a debug message');
Log Formatting
This feature allows you to format log messages by setting a custom name for the logger. The code sample demonstrates how to set a custom name and log an info message with that name.
const { Logger } = require('@slack/logger');
const logger = new Logger();
logger.setName('MyApp');
logger.info('This is an info message with a custom name');
Other packages similar to @slack/logger
winston
Winston is a versatile logging library with support for multiple transports, log levels, and formats. It is more feature-rich compared to @slack/logger and is suitable for more complex logging requirements.
bunyan
Bunyan is a simple and fast JSON logging library. It provides a CLI tool for pretty-printing logs and is designed for high-performance logging. It offers more advanced features compared to @slack/logger.
pino
Pino is a low-overhead logging library that focuses on performance. It provides fast and efficient logging with a simple API. Pino is more performance-oriented compared to @slack/logger.
Slack Logger
The @slack/logger
package is intended to be used as a simple logging interface that supports verbosity levels.
Requirements
This package supports Node v18 and higher. It's highly recommended to use the latest LTS version of
node, and the documentation is written using syntax and features
from that version.
Installation
$ npm install @slack/logger
Usage
This package exports a ConsoleLogger
class, a generic Logger
interface and a LogLevel
enum.
The source code is short (~150 lines of code), so check out src/index.ts
for details, but the ConsoleLogger
API
mimics the default node console
API with three additions:
getLevel()
: returns the currently-specific LogLevel
of the logger.setLevel(LogLevel)
: sets the LogLevel
of the logger.setName(string)
: sets a prefix to display in logs. Useful if you have multiple loggers active.
Getting Help
If you get stuck, we're here to help. The following are the best ways to get assistance working through your issue:
- Issue Tracker for questions, feature requests, bug reports and
general discussion related to this package. Try searching before you create a new issue.
- Email us in Slack developer support:
developers@slack.com